import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home.vue'

Vue.use(VueRouter)


//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = VueRouter.prototype.push;
const originalReplace = VueRouter.prototype.replace;
//push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};
//replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalReplace.call(this, location, onResolve, onReject);
  return originalReplace.call(this, location).catch(err => err);
};






import allChildrenRouters from './modules'
// console.log(allChildrenRouters);
const { myRouterList, billRouter, queryRouter } = allChildrenRouters
const { routerList } = myRouterList
const { billRouterList } = billRouter
const { queryRouterList } = queryRouter


const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      title: '首页',
      isMenu: true
    }
  },
  {
    path: '/query',
    name: 'query',
    component: () => import('../views/query.vue'),
    meta: {
      title: '查询分析',
      isMenu: true
    }
  },
  {
    path: '/bill',
    name: 'bill',
    component: () => import('../views/bill.vue'),
    meta: {
      title: '业务单据',
      isMenu: true
    }
  },
  {
    path: '/me',
    name: 'me',
    component: () => import('../views/me.vue'),
    meta: {
      title: '我的',
      isMenu: true
    }
  },
  ...routerList,
  ...billRouterList,
  ...queryRouterList,


]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
